package org.dromara.system.api.services;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.AssertUtils;
import org.dromara.system.api.domain.vo.RemoteDictDataVo;
import org.dromara.system.api.domain.vo.RemoteDictTypeVo;
import org.dromara.system.api.feign.SystemDictClient;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: zhou shuai
 * @date: 2024/10/6 10:52
 * @version: v1
 */
@Slf4j
@Service("sysDictApiService")
@RequiredArgsConstructor
public class SysDictApiService {

    private final SystemDictClient systemDictClient;

    /**
     * 根据字典类型查询字典类型
     *
     * @param dictType 字典类型
     * @return 字典类型
     */
    public RemoteDictTypeVo selectDictTypeByType(String dictType) {
        R<RemoteDictTypeVo> dictTypeResult = systemDictClient.selectDictTypeByType(dictType);
        AssertUtils.assertTrue(R.isSuccess(dictTypeResult), "根据字典类型查询字典类型失败");
        return dictTypeResult.getData();
    }

    /**
     * 根据字典类型查询字典数据
     *
     * @param dictType 字典类型
     * @return 字典数据集合信息
     */
    public List<RemoteDictDataVo> selectDictDataByType(String dictType) {
        R<List<RemoteDictDataVo>> dictDataListResult = systemDictClient.selectDictDataByType(dictType);
        AssertUtils.assertTrue(R.isSuccess(dictDataListResult), "根据字典类型查询字典数据失败");
        return dictDataListResult.getData();
    }

}
